package demoxsgl_300.com.gouwu1500.zhi;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.util.SparseBooleanArray;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import demoxsgl_300.com.gouwu1500.R;
import demoxsgl_300.com.gouwu1500.adapter.BingZheng_Adapter;
import demoxsgl_300.com.gouwu1500.adapter.YouYing_Adapter;
import demoxsgl_300.com.gouwu1500.bean.Bean;

/**
 * 发作特点
 */
public class YouYin_3_Activity extends Activity {

    @BindView(R.id.textView5)
    TextView textView5;
    @BindView(R.id.imageView2)
    ImageView imageView2;
    @BindView(R.id.imageView3)
    ImageView imageView3;
    @BindView(R.id.lv_list)
    ListView listView;
    @BindView(R.id.wushangshu)
    Button wushangshu;
    @BindView(R.id.queding)
    Button queding;
    YouYing_Adapter faZuo_adapter;
    List<String> ccList = new ArrayList<String>();
    @BindView(R.id.fanhui)
    TextView fanhui;
    List<String> xuanzhonglist = new ArrayList<String>();
    List<Bean.YouyinBean> fazuoteidan;
    StringBuilder stringBuild = new StringBuilder();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fazuotedian);
        ButterKnife.bind(this);
        textView5.setText("加重缓解诱因");
        faZuo_adapter = new YouYing_Adapter(listView);
        listView.setAdapter(faZuo_adapter);

        fazuoteidan = Content.bean.getYouyin();

        if (fazuoteidan != null && fazuoteidan.size() > 0) {
            faZuo_adapter.addItem(fazuoteidan);
        } else {
            Toast.makeText(this, "暂无数据", Toast.LENGTH_SHORT).show();
        }
        listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                                    int position, long id) {

                faZuo_adapter.notifyDataSetChanged();

            }
        });
    }

    @OnClick({R.id.fanhui, R.id.wushangshu, R.id.queding})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.fanhui:
                finish();
                break;
            case R.id.wushangshu:
                Content.YouYin = "";
                 tiaozhuan();
                break;
            case R.id.queding:
                xuanzhonglist.clear();
                SparseBooleanArray booleanArray = listView.getCheckedItemPositions();
                if (booleanArray != null && booleanArray.size() > 0) {
                    for (int j = 0; j < booleanArray.size(); j++) {
                        int key = booleanArray.keyAt(j);
                        //放入SparseBooleanArray，未必选中
                        if (booleanArray.get(key)) {
                            //这样mAdapter.getItem(key)就是选中的项
//                        Log.e("111", "" + key + ": true");
                            xuanzhonglist.add(fazuoteidan.get(key).getName());
                        } else {
                            //这里是用户刚开始选中，后取消选中的项
//                        Log.e("112", "" + key + ": false");
                        }

                    }
                    for (int i = 0; i < xuanzhonglist.size(); i++) {
                        stringBuild.append(xuanzhonglist.get(i) + ",");
                    }
                    Content.YouYin = stringBuild.toString();
                    Log.e("111", "xx" + stringBuild);
                } else {
                    Content.YouYin = "";
                }
                  tiaozhuan();

                break;
        }
    }
    public  void tiaozhuan(){
        startActivity(new Intent(this, BanSuiBingZhengActivity.class));
        finish();
    }
}
